package dao;

import entity.BikeProduct;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;
import utils.DbUtils;
import utils.StringUtils;

import java.sql.SQLException;
import java.util.List;

/**
 * @author lishunlin110
 * @version 1.0
 * @description: 实现BikeProductDao
 * @date 2021/9/2 16:17
 */
public class BikeProductDaoImpl implements BikeProductDao{
    @Override
    public List<BikeProduct> queryBySearchContent(String searchContent) {
        QueryRunner queryRunner = new QueryRunner(DbUtils.getDateSource());
        String sql = "select * from product where brand like ? or p_model like ? or p_name like ?";
        String fuzzy = StringUtils.Fuzzy(searchContent);
        try {
            return  queryRunner.query(sql,new BeanListHandler<>(BikeProduct.class),fuzzy,fuzzy,fuzzy);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return null;
    }
}
